import java.awt.event.KeyEvent;

import light3d.*;

public class TestClass
{
	public static void main(String[] args)
	{
		EngineWindow engineWindow = new EngineWindow("A TEST", 640, 480);
		BufferedCanvas bufferedCanvas = engineWindow; 

		int tex = bufferedCanvas.loadTexture("data/spitfire.jpg");
		
		PointWithAngle camera = new PointWithAngle(0,0,-15);
		camera.rotate(0,0,0);
		camera.finalizeCoordinates();

		WavefrontMesh testMesh = new WavefrontMesh("data/spitfire.obj", tex);
		
		testMesh.translate(0, 0, 0);
		testMesh.rotate(90, 0, 0);
		testMesh.finalizeCoordinates();
		
		final int MAX_RUNS = 3, FRAMES_PER_RUN = 100;
		
		double timePassed = 0.0;
		
		for (int r = 0; r < MAX_RUNS || true; r++)
		{
			for (int f = 0; f < FRAMES_PER_RUN; f++)
			{
				double angle = (f + FRAMES_PER_RUN*r)*360/MAX_RUNS/FRAMES_PER_RUN;
				
				bufferedCanvas.beginRender();
				
				testMesh.rotate(angle, angle*2, 0);
				testMesh.render(bufferedCanvas, camera);
				
				testMesh.resetChanges();
				timePassed = bufferedCanvas.endRender();
				
				if (engineWindow.isPressed(KeyEvent.VK_LEFT))
				{
					//camera.rotate(-90*timePassed, 0, 0);
					camera.rotate(0,-90*timePassed, 0);
					//camera.rotate(0,0,-90*timePassed);
				}

				if (engineWindow.isPressed(KeyEvent.VK_RIGHT))
				{
					//camera.rotate(90*timePassed, 0, 0);
					camera.rotate(0,90*timePassed, 0);
					//camera.rotate(0,0,90*timePassed);
				}
				
				if (engineWindow.isPressed(KeyEvent.VK_UP))
				{
					camera.rotate(-90*timePassed, 0, 0);
				}
				
				if (engineWindow.isPressed(KeyEvent.VK_DOWN))
				{
					camera.rotate(90*timePassed, 0, 0);
				}					
			}
			bufferedCanvas.printStatistics();
		}
		System.exit(0);
	}
}
